using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Database.Hibernate;
using Database.Hibernate.UnitOfWork;
using Infrastructure.Hibernate;
using Infrastructure.UnitOfWork;
using NHibernate;

namespace Host.Inject.IoC
{
    public class UnitOfWorkInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For<IUnitOfWorkFactory>().ImplementedBy<NHibernateUnitOfWorkFactory>());
            container.Register(Component.For<ISessionProvider>().ImplementedBy<SessionProvider>());
            container.Register(Component.For<INHibernateInitializer>().ImplementedBy<FluentInitializer>());
            container.Register(Component.For<ISessionFactory>().UsingFactoryMethod(
                x => x.Resolve<INHibernateInitializer>()
                         .GetConfiguration()
                         .BuildSessionFactory())
                );
        }
    }

}